package com.luoxiang.socialandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.bean.CreditLog;
import com.luoxiang.socialandroid.bean.Recharge;
import com.luoxiang.socialandroid.utils.MmkvUtil;

import java.util.List;

/**
 * @Description TODO
 * @systemUser Administrator
 * @Author LX
 * @Date 09-21-2022 周三 17:23
 */
public class TaocancionAdapter extends RecyclerView.Adapter<TaocancionAdapter.ViewHolder> {
    private View view;
    public List<Recharge> list;
    public int rowindex=0;
    private int payid;
//    public TaocancionAdapter(List<Recharge> list) {
//        this.list = list;
//    }
    public void setData(List<Recharge> list) {
        this.list = list;
    }
    public static interface OnAddClickListener {
        // true add; false cancel
        public void onItemClicks(int position, int payid); //传递boolean类型数据给activity
    }

    SendCoinAdapter.OnAddClickListener onItemAddClick;

    public void setOnAddClickListener(SendCoinAdapter.OnAddClickListener onItemAddClick) {
        this.onItemAddClick = onItemAddClick;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_coinpay, parent, false);
        TaocancionAdapter.ViewHolder holder = new TaocancionAdapter.ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.coincount.setText(list.get(position).getCoin() + "");
        holder.renminbicoin.setText("￥" + list.get(position).getAmount());
        Integer isVip = MmkvUtil.INSTANCE.decodeInt("isVip");
        if (isVip == 0) {
            //不是VIP
            holder.tv_sendnum.setText(holder.tv_sendnum.getContext().getString(R.string.mi_song) + list.get(position).getAliapyGivenCoin() + holder.tv_sendnum.getContext().getString(R.string.mi_bi));

        } else {
            holder.tv_sendnum.setText(holder.tv_sendnum.getContext().getString(R.string.mi_song) + list.get(position).getVipGivenCoin() + holder.tv_sendnum.getContext().getString(R.string.mi_bi));
        }
        MmkvUtil.INSTANCE.encode("id",list.get(0).getId());
        holder.rl_taocanneirong.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rowindex = position;
                notifyDataSetChanged();

            }
        });
        if (rowindex == position) {
            holder.tv_sendnum.setBackgroundResource(R.mipmap.back_blue);
            holder.rl_taocanneirong.setBackgroundResource(R.drawable.shape_backblue);
        } else {
            holder.tv_sendnum.setBackgroundResource(R.mipmap.item_coinefalse);
            holder.rl_taocanneirong.setBackgroundResource(R.drawable.shape_itembuycoin);
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView coincount, renminbicoin, tv_sendnum;
        RelativeLayout rl_taocanneirong;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            coincount = itemView.findViewById(R.id.coincount);
            renminbicoin = itemView.findViewById(R.id.renminbicoin);
            tv_sendnum = itemView.findViewById(R.id.tv_sendnum);
            rl_taocanneirong = itemView.findViewById(R.id.rl_taocanneirong);
        }
    }

}
